package com.aco.party.web.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by WangShijun on 2016/4/23.
 */
@Component
public class NavSelectInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        String requestUrl = request.getRequestURL().toString();
        if(requestUrl.endsWith(".css") || requestUrl.endsWith(".js")) return true;
        if(requestUrl.contains("system")) return true;
        if(!requestUrl.contains("home")) {
            if (requestUrl.contains("product") || requestUrl.contains("people") || requestUrl.contains("company")) {
                request.setAttribute("select", "db");
                return true;
            }
            if (requestUrl.contains("moke")) {
                request.setAttribute("select", "moke");
                return true;
            }
            if (requestUrl.contains("baike") || requestUrl.contains("question")) {
                request.setAttribute("select", "jingnang");
                return true;
            }
            if(requestUrl.contains("event")){
                request.setAttribute("select", "event");
                return true;
            }
            if(requestUrl.contains("hire")){
                request.setAttribute("select", "hire");
                return true;
            }
            if(requestUrl.contains("aboutUs")){
                request.setAttribute("select", "about");
                return true;
            }
            if(requestUrl.contains("posts")){
                request.setAttribute("select", "posts");
                return true;
            }
        }else{
            request.setAttribute("select", "home");
            return true;
        }
        return true;
    }
}
